from typing import Optional

import PySide6.QtCore
import PySide6.QtWidgets
from PySide6.QtWidgets import QWidget
from PySide6.QtCore import Qt

from .Ui_ContainWidget import Ui_ContainWidget


class ContainWidget(QWidget):
    def __init__(self, parent: Optional[PySide6.QtWidgets.QWidget] = None, f: PySide6.QtCore.Qt.WindowFlags = Qt.Widget) -> None:
        super().__init__(parent=parent, f=f)
        self._ui = Ui_ContainWidget()
        self._ui.setupUi(self)
        self._widget = QWidget()
        self.SetWidget(self._widget)
        

    def SetWidget(self, w: 'QWidget') -> None:
        '''
        Function:
            设置本窗体容纳的容器
        args: 
            w: 'QWidget' 要设置的窗体对象
        return:
            None
        '''
        # self._ui.gridLayout.replaceWidget(w, self._widget)
        # print(self._ui.gridLayout.rowCount())
        # self._ui.gridLayout.removeWidget(self._widget)
        # print(self._ui.gridLayout.rowCount())
        # self._ui.gridLayout.addWidget(w, 0, 0)
        self._ui.gridLayout.addWidget(w, 0, 0)
        self._widget = w
        w.show()
    
    def Widget(self) -> 'QWidget':
        '''
        Function:
            获取本窗体内部的窗体对象
        args: 
            None
        return:
            QWidget 本容器窗体内部的窗体对象
        '''
        return self._widget
